#-*- coding: utf-8 -*-
import itertools
from datetime import datetime

from django.db import models
from django.contrib.contenttypes import generic
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType

import xunit
#from map.models import *
#from rules import *

#class Settlement(AbstractCellContent):
#    """
#    The settlement on the cell
#    """
#    owner = models.ForeignKey(User, blank=True, null=True)
#    name = models.CharField(max_length=25)
#
#    #resources in storage
#    corn = models.PositiveIntegerField(default=100)
#    iron = models.PositiveIntegerField(default=200)
#    clay = models.PositiveIntegerField(default=200)
#    wood = models.PositiveIntegerField(default=200)
#
#    #resource upgrage speed by one hour
#    corn_speed = models.PositiveIntegerField(default=0)
#    iron_speed = models.PositiveIntegerField(default=0)
#    clay_speed = models.PositiveIntegerField(default=0)
#    wood_speed = models.PositiveIntegerField(default=0)
#
#    last_resource_update_time = models.DateTimeField(auto_now=True)
#
#    # storage capacity
#    corn_max_storage = 200
#    resources_max_storage = 1000
#
#    @models.permalink
#    def get_absolute_url(self):
#        return ('suburb',  [self.pk])
#
#    def image(self):
#        return "S"
#
#    def resources(self):
#        """
#        Actual resource quantities
#        """
#        calc_time = datetime.now()
#        time_gap = calc_time - self.last_resource_update_time()
#        gap_hours = time_gap.days*24 + time_gap.seconds/3600.0
#        return calc_time, \
#            {GroundSlot.TYPE.CORN : self.corn + int(self.corn_speed*gap_hours),
#             GroundSlot.TYPE.IRON : self.iron + int(self.iron_speed*gap_hours),
#             GroundSlot.TYPE.CLAY : self.clay + int(self.clay_speed*gap_hours),
#             GroundSlot.TYPE.WOOD : self.wood + int(self.wood_speed*gap_hours)}
#
#    
#    def update_resources(self, corn = 0, iron = 0, clay = 0, wood = 0):
#        """
#        Resource quantities calculation and updating
#        """
#        calc_time, current_resources = self.resources()
#        self.corn = current_resources[GroundSlot.TYPE.CORN] - corn
#        self.iron = current_resources[GroundSlot.TYPE.IRON] - iron
#        self.clay = current_resources[GroundSlot.TYPE.CLAY] - clay
#        self.wood = current_resources[GroundSlot.TYPE.WOOD] - wood
#        self.last_resource_update_time = calc_time
#
#    def update_gather_speed(self):
#        """
#        Resource growth speed calculation and updating
#        """
#        #update resource speed
#        ground = GroundSlot.object.filter(settlement=self).order_by(ground_type)
#
#
#    @staticmethod
#    def any():
#        result = Settlement()
#        result.owner = User.any()
#        result.name = xunit.any_string(max_length=25)
#        return result
#
#
#class Lowland(AbstractCellContent):
#    """
#    Spare land
#    """
#    @models.permalink
#    def get_absolute_url(self):
#        return ('lowland',  [self.pk])
#
#    def image(self):
#        return "L"
#
#    @staticmethod
#    def any():
#        return Lowland()
#
#
#class GroundSlot(models.Model):
#    """
#    Resource mine
#    """
#    settlement = models.ForeignKey(Settlement)
#    position = models.PositiveIntegerField()
#    level = models.PositiveIntegerField(default=0)
#    ground_type = models.CharField(
#        max_length=4, choices=GROUND_TYPE.CHOICES)
#
#    def image(self):
#        return self.ground_type[:2]
#
#    def can_be_upgraded(self):
#        return self.level < len(GROUND_RULES[self.ground_type])
#
#    def next_level(self):
#        return self.level+1
#
#
#class BuildingSlot(models.Model):
#    """
#    Settlement building
#    """
#    settlement = models.ForeignKey(Settlement)
#    position = models.PositiveIntegerField()
#    level = models.PositiveIntegerField(default=0)
#    building_type = models.CharField(
#        max_length=4, choices=BUILDING_TYPE.CHOICES)
#
#    def image(self):
#        return self.building_type[0]
#
#
#class Queue(models.Model):
#    do_time = models.DateTimeField()
#    create_time = models.DateTimeField(auto_now_add=True)
#    description = models.CharField(max_length=250)
#    action = models.TextField(help_text='One of serialized Action instance')
#
#
